package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@SuppressWarnings("all")
@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间ID查询床位", notes = "传入房间ID，返回该房间内所有床位的信息")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }

    @PostMapping("/create")
    @ApiOperation(value = "创建床位", notes = "传入床位编号、排序号、房间ID，创建新的床位信息")
    public ResponseResult addBed(@ApiParam(value = "床位信息", required = true) @RequestBody BedDto bedDto) {
        bedService.addBed(bedDto);
        return success();
    }

    @GetMapping("/read/{id}")
    @ApiOperation(value = "根据ID查询床位", notes = "传入床位ID，返回该床位的详细信息")
    public ResponseResult<BedVo> getBed(@ApiParam(value = "床位ID", required = true) @PathVariable Long id) {
        BedVo bedVo = bedService.getBed(id);
        return success(bedVo);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除床位", notes = "传入床位ID，删除对应的床位信息")
    public ResponseResult deleteBedById(@ApiParam(value = "床位ID", required = true) @PathVariable Long id) {
        bedService.deleteBedById(id);
        return success();
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新床位", notes = "传入床位ID及修改后的信息, 更新数据库中的对应床位信息")
    public ResponseResult updateBed(@RequestBody BedDto bedDto) {
        bedService.updateBed(bedDto);
        return success();
    }
}